package com.bishe.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bishe.entity.LogisticsInfo;
import com.bishe.entity.WzInfo;
import com.bishe.entity.response.R;
import com.bishe.service.LogisticsInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (LogisticsInfo)表控制层
 *
 * @author makejava
 * @since 2024-03-04 00:02:36
 */
@CrossOrigin
@RestController
@RequestMapping("logisticsInfo")
public class LogisticsInfoController {
    /**
     * 服务对象
     */
    @Resource
    private LogisticsInfoService logisticsInfoService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param logisticsInfo 查询实体
     * @return 所有数据
     */
    @GetMapping("/toPage")
    @ApiOperation("分页查询")
    public R selectAll(Page<LogisticsInfo> page, LogisticsInfo logisticsInfo) {
        LambdaQueryWrapper<LogisticsInfo> queryWrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotEmpty(logisticsInfo.getOrderNo())){
            queryWrapper.eq(LogisticsInfo::getOrderNo,logisticsInfo.getOrderNo());
        }

        if (StrUtil.isNotEmpty(logisticsInfo.getPhone())){
            queryWrapper.eq(LogisticsInfo::getPhone,logisticsInfo.getPhone());
        }
        queryWrapper.orderByDesc(LogisticsInfo::getCreateTime);
        return R.ok(this.logisticsInfoService.page(page, queryWrapper));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation("通过主键查询单条数据")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.logisticsInfoService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param logisticsInfo 实体对象
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation("新增数据")
    public R insert(@RequestBody LogisticsInfo logisticsInfo) {
        return R.ok(this.logisticsInfoService.save(logisticsInfo));
    }

    /**
     * 修改数据
     *
     * @param logisticsInfo 实体对象
     * @return 修改结果
     */
    @PutMapping
    @ApiOperation("修改数据")
    public R update(@RequestBody LogisticsInfo logisticsInfo) {
        return R.ok(this.logisticsInfoService.updateById(logisticsInfo));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    @ApiOperation("删除数据")
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(this.logisticsInfoService.removeByIds(idList));
    }
}

